package com.walter.common.basic;

import com.walter.common.exception.AppHttpCodeEnum;
import lombok.Data;

import java.io.Serializable;

/**
 * @author Walter
 * @date 2025/1/20 上午9:03
 **/
@Data
public class ResultVO<T> implements Serializable {
    private Boolean success;
    private Integer code;
    private String msg;
    private T data;

    public static <T> ResultVO<T> success(T data) {
        ResultVO<T> resultVO = new ResultVO<>();
        resultVO.setSuccess(true);
        resultVO.setCode(AppHttpCodeEnum.SUCCESS.getCode());
        resultVO.setMsg(AppHttpCodeEnum.SUCCESS.getMessage());
        resultVO.setData(data);
        return resultVO;
    }
    public static <T> ResultVO<T> success() {
        return success(null);
    }
    public static <T> ResultVO<T> fail(Integer code, String msg) {
        ResultVO<T> resultVO = new ResultVO<>();
        resultVO.setSuccess(false);
        resultVO.setCode(code);
        resultVO.setMsg(msg);
        return resultVO;
    }
    public static <T> ResultVO<T> fail(AppHttpCodeEnum appHttpCodeEnum) {
        return fail(appHttpCodeEnum.getCode(), appHttpCodeEnum.getMessage());
    }
    public static <T> ResultVO<T> fail(String msg) {
        return fail(AppHttpCodeEnum.FAIL.getCode(),msg);
    }
}
